package com.istudy.service.imp;

import com.istudy.dao.xyjdao.UserIntDao;
import com.istudy.dao.xyjdao.impl.UserImplDao;
import com.istudy.utils.JDBCUtils;

import java.sql.SQLException;

/**
 * @author xdd
 * @create 2020-09-03 15:12
 */
public class XYJUserServiceImp {
    UserIntDao userIntDao=new UserImplDao(JDBCUtils.getConnection());


    /**
     * 根据指定用户进行相应扣费
     *
     * @param userId       用户id
     * @param videoConsume 扣费金额
     * @return 是否成功
     */
    public boolean UserDeduction(String userId, String videoConsume) {
        int userIdInt = 0;
        int videoConsumeInt = 0;
        try {
            userIdInt = Integer.parseInt(userId);
            videoConsumeInt = Integer.parseInt(videoConsume);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("User业务逻辑层扣费异常，无法转换参数");
        }
        try {
            int i = userIntDao.UserDeduction(userIdInt, videoConsumeInt);
            if (i == 1) {
                return true;//扣费成功
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;//扣费失败
    }

}
